package com.wnxy.admin.controller;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.dto.AlarmMessageDto;
import com.wnxy.admin.dto.PageResult;
import com.wnxy.admin.dto.RuleQueryDto;
import com.wnxy.admin.entity.AlarmSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.wnxy.admin.entity.AlarmMessages;
import com.wnxy.admin.service.IAlarmMessagesService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/alarm-messages")
public class AlarmMessagesController {

    private final IAlarmMessagesService alarmMessagesServiceImpl;
    public AlarmMessagesController(IAlarmMessagesService alarmMessagesServiceImpl){
        this.alarmMessagesServiceImpl = alarmMessagesServiceImpl;
    }

    /*
     *  数据导出
     * */
    @GetMapping("/export")
    public void export(ModelMap map,
                       HttpServletRequest request,
                       HttpServletResponse response) {
        List<AlarmMessages> alarmMessagesList = alarmMessagesServiceImpl.list();
        ExportParams params = new ExportParams("报警消息列表", "报警消息列表", ExcelType.XSSF);
        map.put(NormalExcelConstants.DATA_LIST, alarmMessagesList);
        map.put(NormalExcelConstants.CLASS, AlarmMessages.class);
        map.put(NormalExcelConstants.PARAMS, params);
        map.put(NormalExcelConstants.FILE_NAME, "alarmMessagesList");
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
    }

    /*
     *  取消任务
     * */
    @PostMapping("/cancelTask")
    public ResponseResult cancelTask(@RequestBody AlarmMessages alarmMessages) {
        alarmMessagesServiceImpl.cancelTask(alarmMessages);
        return ResponseResult.ok();
    }

    /*
    *  发起任务
    * */
    @PostMapping("/startTask")
    public ResponseResult startTask(@RequestBody AlarmMessages alarmMessages) {
        alarmMessagesServiceImpl.startTask(alarmMessages);
        return ResponseResult.ok();
    }

    /*
     *  查询报警消息(分页)
     * */
    @GetMapping("/queryAlarmMessage")
    public ResponseResult queryAlarmMessage(@ModelAttribute AlarmMessageDto alarmMessageDto) {
        PageResult page = alarmMessagesServiceImpl.queryAlarmMessage(alarmMessageDto);
        return ResponseResult.ok(page);
    }

}
